import { Entity, Column, OneToMany } from 'typeorm';
import { BaseEntity } from './baseEntity';
import { TArticleComment } from './article-comment.entity';

/**
 * @description: 文章表
 */

@Entity()
export class TArticle extends BaseEntity {
  //   文章标题
  @Column({ type: 'varchar', length: 255, name: 'title', comment: '文章标题' })
  title: string;

  //   文章封面
  @Column({
    type: 'varchar',
    length: 255,
    name: 'cover_image',
    comment: '文章封面',
    nullable: true,
  })
  coverImage?: string;

  //   文章URL友好标识
  @Column({
    type: 'varchar',
    length: 255,
    name: 'slug',
    comment: '文章URL友好标识',
    nullable: true,
  })
  slug?: string;

  //   关联用户id
  @Column({
    type: 'bigint',
    name: 'author_id',
    comment: '关联用户id',
    nullable: true,
  })
  authorId?: number | string;

  //   文章状态：draft（草稿）、published（已发布）、deleted（已删除）
  @Column({
    type: 'varchar',
    name: 'status',
    comment: '文章状态：draft（草稿）、published（已发布）、deleted（已删除）',
  })
  status: string;

  //   发布日期
  @Column({
    type: 'datetime',
    name: 'published_at',
    comment: '发布日期',
    nullable: true,
  })
  publishedAt?: string;

  //   正文
  @Column({
    type: 'longtext',
    name: 'content',
    comment: '正文',
  })
  content: string;

  //   摘要
  @Column({
    type: 'varchar',
    name: 'summary',
    comment: '摘要',
    nullable: true,
  })
  summary?: string;

  //   分类id
  @Column({
    type: 'varchar',
    name: 'category_id',
    comment: '分类id',
    nullable: true,
  })
  categoryId?: string;

  //   标签
  @Column({
    type: 'varchar',
    name: 'tags',
    comment: '标签分类',
    nullable: true,
  })
  tags?: string;

  //   阅读量
  @Column({
    type: 'varchar',
    name: 'views',
    comment: '阅读量',
  })
  views: string;

  //   点击量
  @Column({
    type: 'varchar',
    name: 'likes',
    comment: '点击量',
  })
  likes: string;

  //   评论量
  @Column({
    type: 'varchar',
    name: 'comments_count',
    comment: '评论量',
  })
  commentsCount: string;

  //   是否允许评论
  @Column({
    type: 'varchar',
    name: 'is_comment_enabled',
    comment: '是否允许评论',
  })
  isCommentEnabled: string;

  //   是否置顶
  @Column({
    type: 'varchar',
    name: 'is_top',
    comment: '是否置顶',
  })
  isTop: string;

  //    推荐权重（数值越大排名越靠前）
  @Column({
    type: 'varchar',
    name: 'recommend_weight',
    comment: '推荐权重（数值越大排名越靠前）',
  })
  recommendWeight: string;

  //   评论
  @OneToMany(() => TArticleComment, (comment) => comment.article)
  comments: TArticleComment[];
}
